package com.spic.business.plan.exercisePlan.service.impl;

import com.spic.business.common.datascope.anotation.BusinessDataScope;
import com.spic.business.plan.exercisePlan.domain.PlanExercisePlan;
import com.spic.business.plan.exercisePlan.mapper.PlanExercisePlanMapper;
import com.spic.business.plan.exercisePlan.service.IPlanExercisePlanService;
import com.spic.common.core.utils.DateUtils;
import com.spic.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * 应急演练计划Service业务层处理
 *
 * @author spic
 * @date 2021-11-09
 */
@Service
public class PlanExercisePlanServiceImpl implements IPlanExercisePlanService
{
    @Autowired
    private PlanExercisePlanMapper planExercisePlanMapper;

    /**
     * 查询应急演练计划
     *
     * @param id 应急演练计划主键
     * @return 应急演练计划
     */
    @Override
    public PlanExercisePlan selectPlanExercisePlanById(String id)
    {
        return planExercisePlanMapper.selectPlanExercisePlanById(id);
    }

    /**
     * 查询应急演练计划列表
     *
     * @param planExercisePlan 应急演练计划
     * @return 应急演练计划
     */
    @Override
    @BusinessDataScope(menuPath = "business/plan/exercisePlan/index")
    public List<PlanExercisePlan> selectPlanExercisePlanList(PlanExercisePlan planExercisePlan)
    {
        return planExercisePlanMapper.selectPlanExercisePlanList(planExercisePlan);
    }

    /**
     * 新增应急演练计划
     *
     * @param planExercisePlan 应急演练计划
     * @return 结果
     */
    @Override
    public String insertPlanExercisePlan(PlanExercisePlan planExercisePlan)
    {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        planExercisePlan.setId(uuid);
        planExercisePlan.setCreatBy(SecurityUtils.getUserId());
        planExercisePlan.setCreateTime(DateUtils.getNowDate());
        planExercisePlanMapper.insertPlanExercisePlan(planExercisePlan);
        return uuid;
    }

    /**
     * 修改应急演练计划
     *
     * @param planExercisePlan 应急演练计划
     * @return 结果
     */
    @Override
    public int updatePlanExercisePlan(PlanExercisePlan planExercisePlan)
    {
        planExercisePlan.setUpdateTime(DateUtils.getNowDate());
        planExercisePlan.setUpdateBy(SecurityUtils.getUsername());
        return planExercisePlanMapper.updatePlanExercisePlan(planExercisePlan);
    }

    /**
     * 批量删除应急演练计划
     *
     * @param ids 需要删除的应急演练计划主键
     * @return 结果
     */
    @Override
    public int deletePlanExercisePlanByIds(String[] ids)
    {
        return planExercisePlanMapper.deletePlanExercisePlanByIds(ids);
    }

    /**
     * 删除应急演练计划信息
     *
     * @param id 应急演练计划主键
     * @return 结果
     */
    @Override
    public int deletePlanExercisePlanById(String id)
    {
        return planExercisePlanMapper.deletePlanExercisePlanById(id);
    }
}
